package cn.wwcyc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.wwcyc.domain.Rolemenu;
import cn.wwcyc.service.RolemenuService;
import cn.wwcyc.mapper.RolemenuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @author z
* @description 针对表【ROLEMENU】的数据库操作Service实现
* @createDate 2023-10-24 10:30:25
*/
@Service
public class RolemenuServiceImpl extends ServiceImpl<RolemenuMapper, Rolemenu>
    implements RolemenuService{
    @Autowired
    RolemenuMapper rmm;

    @Override
    public List<Integer> getMenusByRoleId(Integer roleId) {
        List<Integer> menuIdList = rmm.selectMenuIdByRoleId(roleId);
        return menuIdList;
    }

    @Override
    @Transactional
    public void setRoleMenu(Integer roleId, List<Integer> menuIds) {
        QueryWrapper<Rolemenu> qw = new QueryWrapper();
        qw.eq("roleid", roleId);
        rmm.delete(qw);
        for(Integer menuId : menuIds){
            Rolemenu rm = new Rolemenu();
            rm.setMenuid(menuId.longValue());
            rm.setRoleid(roleId.longValue());
            rmm.insert(rm);
        }
    }
}




